<template>
  <view class="incomeListMain">
    <view class="incomeListBox">
      <!-- 列表 -->
      <view v-if="list.length > 0">
        <view
          class="incomelistItem"
          v-for="(item, index) in list"
          :key="index"
        >
          <view class="topBox solid-bottom flex align-center justify-between">
             <view class="topLeft">
                <view v-if="item.mercNm">{{item.mercNm}}</view>
                <text v-if="item.productNm">{{item.number}}</text>
             </view>
             <view class="topRight">
                {{ item.type }}
             </view>
          </view>
          <view class="subBox flex align-center justify-between">
             <view class="subLeft">
				<view>商户名称：{{ item.mercNm }}</view>
                <view>交易金额：<text>{{ item.money }}</text></view>
                <view>交易时间：{{ $u.timeFormat(item.create_time, "yyyy-mm-dd hh:MM:ss") }}</view>
                <view>交易单号：{{ item.orderNo }}</view>
             </view>
             <view class="subRight">
                <text>+</text>{{ item.revert_money }}
             </view>
          </view>
        </view>
      </view>
      <!-- 暂无数据 -->
      <view
        class="noMachine flex align-center"
        v-if="list.length == 0 && isLoad"
      >
        <image
          src="../../static/images/noData/zwjl.png"
          mode="widthFix"
        ></image>
        <text>暂无收益</text>
      </view>
    </view>
    <u-loadmore
      :status="status"
      @loadmore="loadmore"
      v-if="list.length > 0"
      style="padding: 40rpx 0"
    />
    <toast></toast>
    <u-back-top :scroll-top="scrollTop"></u-back-top>
  </view>
</template>

<script>
export default {
  data() {
    return {
      scrollTop: 0,
      page: 1,
      limit: 15,
      list: [],
      status: "loadmore",
      noMore: false,
      isLoad: false, curTime: this.$route.query.date
    };
  },
  onLoad() {
    console.log(this.$route.query.date);
    this.incomeList();
  },
  onPageScroll(e) {
    this.scrollTop = e.scrollTop;
  },
  onPullDownRefresh() {
    this.page = 1;
    this.list = [];
    this.status = "loadmore";
    this.noMore = false;
    this.isLoad = false;
    this.incomeList();
  },
  onReachBottom() {
    if (this.noMore) {
      this.status = "nomore";
    } else {
      this.status = "loading";
      this.page = ++this.page;
      this.incomeList();
    }
  },
  // 点击下载更多
  loadmore() {
    if (this.noMore) {
      this.status = "nomore";
    } else {
      this.page = ++this.page;
      this.status = "loadmore";
      this.incomeList();
    }
  },
  methods: {
    incomeList() {
      this.$u.api
        .incomeList({
          page: this.page,
          limit: this.limit,
            curTime:this.curTime
        })
        .then((res) => {
          if (res.status == 200) {
            let datas = res.result;
            if (this.page == 1 && datas.length == 0) {
              this.noMore == true;
              this.status = "nomore";
            }
            if (this.page == 1 && datas.length < this.limit) {
              this.noMore == true;
              this.status = "nomore";
            }
            if (this.page > 1 && datas.length < this.limit) {
              this.noMore == true;
              this.status = "nomore";
            }
            if (this.page > 1 && datas.length == this.limit) {
              this.status = "loading";
            }
            this.list = this.list.concat(datas);
          } else {
            this.$refs.uToast.show({
              title: res.msg,
              type: "error",
              duration: 1200,
            });
          }
          this.isLoad = true;
          uni.stopPullDownRefresh();
        })
        .catch((res) => {
          if (res.errMsg == "request:fail timeout") {
            this.$u.toast("请求超时，请重试!");
          } else if (res.errMsg == "request:fail") {
            this.$u.toast("请求失败，请重试");
          } else {
             this.$u.toast("请求失败，请重试");
          }
          this.$loading(false);
          setTimeout(() => {
            this.$u.route({
              type: "navigateBack",
              delta: 1,
            });
          }, 2000);
        });
    },
  },
};
</script>

<style lang="scss">
page {
  background: #fff;
}
.incomeListMain {
  padding:30rpx;
  .incomelistItem {
    padding:20rpx 30rpx 28rpx;
    margin-bottom:30rpx;
    box-shadow:0 0 10rpx #f1f1f1;
    border-radius:10rpx;
    .topBox{
      padding-bottom:20rpx;
      .topLeft{
        >view{
          font-weight:bold;
          font-size:32rpx;
        }
        >text{
          color:#999;
        }
      }
      .topRight{
        padding:5rpx 16rpx;
        background:#fb4535;
        color:#fff;
        font-size:24rpx;
        border-radius:8rpx;
      }
    }
    .subBox{
      padding-top:20rpx;
      .subLeft{
        view{
          font-size:24rpx;
          line-height:36rpx;
          text{
            color:#fb4535;
          }
        }
      }
      .subRight{
        font-size:40rpx;
        font-weight:bold;
        color:#fb4535;
      }
    }
  }
}
</style>
